﻿namespace Chain.Wechat
{
    using System;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Xml;

    public class NewsResponse : IResponse
    {
        
        private int _ArticleCount;
        
        private List<NewsResponseItem> _List;

        public NewsResponse(IRequest req, List<NewsResponseItem> list) : base(req)
        {
            base.Request = req;
            this.List = list;
            if (list != null)
            {
                this.ArticleCount = list.Count;
            }
            else
            {
                this.ArticleCount = 0;
            }
            XmlNode xml = base.XmlDoc.GetElementsByTagName("xml")[0];
            XmlElement nodeMsgType = base.XmlDoc.CreateElement("MsgType");
            XmlCDataSection xmlCData = base.XmlDoc.CreateCDataSection("news");
            nodeMsgType.AppendChild(xmlCData);
            xml.AppendChild(nodeMsgType);
            XmlElement nodeContent = base.XmlDoc.CreateElement("ArticleCount");
            xmlCData = base.XmlDoc.CreateCDataSection(list.Count.ToString());
            nodeContent.AppendChild(xmlCData);
            xml.AppendChild(nodeContent);
            XmlElement nodeArticles = base.XmlDoc.CreateElement("Articles");
            foreach (NewsResponseItem newResponseItem in list)
            {
                XmlNode node = newResponseItem.XmlDoc.FirstChild;
                XmlNode newItem = base.XmlDoc.ImportNode(node, true);
                nodeArticles.AppendChild(newItem);
            }
            xml.AppendChild(nodeArticles);
        }

        public int ArticleCount
        {
            
            get
            {
                return this._ArticleCount;
            }
            
            set
            {
                this._ArticleCount = value;
            }
        }

        public List<NewsResponseItem> List
        {
            
            get
            {
                return this._List;
            }
            
            set
            {
                this._List = value;
            }
        }
    }
}

